package araxy.blog.controller;

import araxy.blog.service.ArticleService;
import com.github.pagehelper.IPage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/article")
public class ArticlesController {

    @Resource
    ArticleService articleService;

    @GetMapping("/{id}")
    public byte[] getArticleRawBytesDataById(@PathVariable String id, HttpServletResponse response) {
        response.reset();
        response.setHeader("Content-Type", "octet-stream");
        response.setHeader("Content-Disposition","attachment");
        return articleService.getArticleBytesById(id);
    }

    @GetMapping("/brief/{page}p/{pageSize}")
    public Object getPagedArticleInfo(@PathVariable Integer page,@PathVariable Integer pageSize) {
        return articleService.getPagedArticleInfo(page,pageSize);
    }

}
